let clock, scene, camera, renderer, container;

function chuShiHua() {

	let width = Math.max(window.innerWidth, window.innerHeight);
	let height = Math.min(window.innerWidth, window.innerHeight);

	clock = new THREE.Clock();

	scene = new THREE.Scene();
	//发光特效下不能设置场景背景色
	// scene.background = new THREE.Color(0xddddff);
	scene.fog = new THREE.FogExp2(0x000000, 0.001);

	camera = new THREE.PerspectiveCamera(60, width / height, 0.1, 1000);
	scene.add(camera);

	renderer = new THREE.WebGLRenderer({
		antialias: true
	});
	renderer.setPixelRatio(window.devicePixelRatio);
	renderer.setSize(width, height);
	renderer.shadowMap.enabled = true;
	renderer.shadowMap.type = THREE.VSMShadowMap;
	
	renderer.localClippingEnabled = true
	
	// renderer.toneMapping = THREE.ReinhardToneMapping;
	// renderer.toneMappingExposure = Math.pow(1, 4.0);//1-2 发光用

	container = document.getElementById('container');
	container.appendChild(renderer.domElement);

	const ambientLight = new THREE.AmbientLight(0xddaaaa, 0.6);
	scene.add(ambientLight);

	const fillLight1 = new THREE.DirectionalLight(0x999999, 0.5);
	fillLight1.position.set(-1, 1, 0);
	scene.add(fillLight1);

	const fillLight2 = new THREE.DirectionalLight(0x888888, 0.5);
	fillLight2.position.set(1, 1, 0);
	scene.add(fillLight2);

	const directionalLight = new THREE.DirectionalLight(0xffffff, 2);
	directionalLight.position.set(2, 40, 10);
	directionalLight.castShadow = true;
	let d = 50;
	directionalLight.shadow.camera.near = 0.01;
	directionalLight.shadow.camera.far = 100;
	directionalLight.shadow.camera.right = d;
	directionalLight.shadow.camera.left = -d;
	directionalLight.shadow.camera.top = d;
	directionalLight.shadow.camera.bottom = -d;
	directionalLight.shadow.mapSize.width = 1024;
	directionalLight.shadow.mapSize.height = 1024;
	directionalLight.shadow.radius = 4;
	directionalLight.shadow.bias = -0.00006;
	scene.add(directionalLight);

	// audio

	const audioLoader = new THREE.AudioLoader();

	const listener = new THREE.AudioListener();
	const audio = new THREE.Audio(listener);
	camera.add(listener);

	// audioLoader.load('/shengYin/beiJingYin.mp3', function(buffer) {

	// 	audio.setBuffer(buffer);
	// 	audio.setVolume(0.4); //音量
	// 	audio.play();
	// 	audio.setLoop(true); //音量

	// });

	return {
		clock,
		scene,
		camera,
		renderer,
		listener,
		audioLoader
	}
}

export default chuShiHua;
